{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "017e8209",
   "metadata": {},
   "source": [
    "* 日期：2022.10.12\n",
    "* 记录人：liyuanyuan"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "59f563c5",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1. 有序的数据结构-字符串\n",
    ">> 1. 字符串的基本概念（回顾）\n",
    ">>> 1. Single queotes:'allows embedded\"double\"quotes'\n",
    ">>> 2. Double quotes: \"allows embedded 'single' quotes\"\n",
    ">>> 3. Triple quoted: '''Three single quotes''', \"\"\"Three double quotes\"\"\"\n",
    ">> 2. 字符串的性质和方法\n",
    "> 2. 有序的数据结构-列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f187b0b8",
   "metadata": {},
   "source": [
    "## 1.字符串的性质和方法\n",
    "\n",
    "* 字符串的性质\n",
    "\n",
    "> 1. 字符串的有序性\n",
    "> 2. 字符串是有长度的\n",
    ">> 1. 使用len()检查字符串的长度\n",
    "* 字符串的基础方法（运算法则）\n",
    "> 1. 字符串的取值：str[index]\n",
    "> 2. 字符串的切片：str[start,stop],stop取不到\n",
    "> 3. 字符串的拼接：+\n",
    "> 4. in检查成员是否存在\n",
    "* 字符串的一般方法（function/Methods函数/方法）\n",
    "> 1. isdigit()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "aed328da",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"广州南方学院团委\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "30eb547a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5e5a1647",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'委'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e2c67ab6",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "string index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [5]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mtext\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mIndexError\u001b[0m: string index out of range"
     ]
    }
   ],
   "source": [
    "text[100]      #字符串是有范围的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d63cfe26",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e295664e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:6]  #等价于[;6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "89f0c857",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0a37b95e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院团'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-3:-1]    #从小到大排"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "9f857e2a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1:-3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "603c41d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ae2c748c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委广州南方学院团委广州南方学院团委'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7439edd",
   "metadata": {},
   "source": [
    "* in 检查成员对象\n",
    "* count()检查字符串出现的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1cd2684f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\" in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9bcafeb5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"北京\" in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "0ab4b969",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text.count(\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7b76b8f0",
   "metadata": {},
   "source": [
    "* isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "405b075f",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_1 = 19\n",
    "age_2 = \"19\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "1183ca19",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(age_1,type(age_1))\n",
    "print(age_2,type(age_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "d3561186",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "# 如果字符串是数值，可以用int转换成真正的数值\n",
    "if age_2.isdigit():\n",
    "    print(age_1 + int(age_2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "39c70779",
   "metadata": {},
   "source": [
    "## 2. 有序的数据结构-列表（list)\n",
    "* 1. 列表的概念和基本性质\n",
    "> 1. Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type.\n",
    "* 2. 列表一般方法（如何学习）\n",
    "> 1.使用.Tab键查看列表的方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6443366",
   "metadata": {},
   "source": [
    "### 2.1列表的性质\n",
    "\n",
    "* 和字符串的运算法则完全一致\n",
    "* 注意：字符串是对字符进行操作，列表是对items元素进行操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "f6d18af5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表的形式\n",
    "squares = [1,4,9,16,25] #列表里放数值\n",
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "12d80fab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "ad178170",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 in squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "0148c609",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares.count(9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "0200fe66",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['ll', 'kk']"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"ll\",\"kk\"]  #列表里放字符串\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "7f6df29d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['ll', 18, 'kk', 20]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info = [\"ll\",18,\"kk\",20]\n",
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "71de979e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 'll', 'kk']"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares + names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "1bf21cdc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2*squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "80695aaa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16]"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "c4a456fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"jack\",\"alex\",\"marry\",\"jan\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "bcda2a6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'marry']"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出”Jack“，”marry“用切片的方法\n",
    "names[:3:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "036127b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "names."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "309d4e2f",
   "metadata": {},
   "source": [
    "* 2. 列表的一般方法(如何学习）\n",
    "> 1. 增加\n",
    "> 2. 删除\n",
    "> 3. 改\n",
    "> 4. 查：in\n",
    "* 列表的学习方法（步骤）\n",
    "> 1. 使用.Tab键查看列表的方法\n",
    "> 2. 使用help（查看方法的使用规则）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "8238ba03",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "de4248cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"李华\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "3fb01d76",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'alex', 'marry', 'jan', '李华']"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb4810d5",
   "metadata": {},
   "source": [
    "# 课后作业\n",
    "* 列表的方法尝试所有的方法\n",
    "* 总结列表的方法学习心得（表格形式总结） | 列表的方法 | Description |使用方法 | 备注 | | ----------- | ----------- |----------- |----------- | | append | Append object to the end of the list. |list.append(object)|注意：增加在末尾！| | Paragraph | Text |Text |Text |"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "070c56d0",
   "metadata": {},
   "source": [
    "## 一、尝试列表的所有方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70b3e160",
   "metadata": {},
   "source": [
    "### 列表切片 name[start:stop:step]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "8c2757de",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = ['列','表','你','切','不','切']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e16e8bc9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '表', '你']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[0:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "5e2c6bc8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '表', '你']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "85ab9506",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '表', '你', '切', '不', '切']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "16bdde1b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['切', '不']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "54a2a519",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['切', '不', '切']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[-3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "5d2b2dd5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '你', '不']"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[0:5:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1316a6f4",
   "metadata": {},
   "source": [
    "### 增  extend(),append()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "f7d02aef",
   "metadata": {},
   "outputs": [],
   "source": [
    "name.extend(\"你猜\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "6805f51a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '表', '你', '切', '不', '切', '你', '猜']"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "a00a00ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '表', '你', '切', '不', '切', '你', '猜', '呗呗']"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.append(\"呗呗\")\n",
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "beeb6dcc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '表', '你', '切', '不', '切', '你', '猜', '呗呗', '你猜我猜不猜']"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.extend([\"你猜我猜不猜\"])\n",
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "5223032f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '表', '你', '切', '不', '切', '你', '猜', '呗呗', '你猜我猜不猜', ['我不猜']]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.append([\"我不猜\"])\n",
    "name"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "094a4c25",
   "metadata": {},
   "source": [
    "### 插  insert()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "9b08ab7f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '插入1', '表', '你', '切', '不', '切']"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = ['列','表','你','切','不','切']\n",
    "name.insert(1,\"插入1\")\n",
    "name"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a348dcd",
   "metadata": {},
   "source": [
    "### 删  remove(),pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "ad4b48fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '表', '你', '不', '切']"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = ['列','表','你','切','不','切']\n",
    "name.remove('切')\n",
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "460c3654",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '表', '你', '不', '切']"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = ['列','表','你','切','不','切']\n",
    "name.pop(3)\n",
    "name"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b27210d8",
   "metadata": {},
   "source": [
    "### 清  clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "0ac250c3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.clear()\n",
    "name"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5ebea8f",
   "metadata": {},
   "source": [
    "### 改  name[索引值] = \"想要替换的内容“"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "46863398",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['列', '列', '你', '切', '不', '切']"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[1] = \"列\"\n",
    "name"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "105ad030",
   "metadata": {},
   "source": [
    "### 查  in,count(),index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "e6f5db86",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = ['列','表','你','切','不','切']\n",
    "'你' in name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "6a80b8d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = ['列','表','你','切','不','切']\n",
    "name.count('你')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "249dee2e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = ['列','表','你','切','不','切']\n",
    "name.index('切')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d876aff2",
   "metadata": {},
   "source": [
    "### 排序  sort(),reverse(reverse = True/False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "d0e4db01",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 4, 5, 9]"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = [2,4,1,9,5]\n",
    "name.sort()\n",
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "745c2505",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 9, 1, 4, 2]"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = [2,4,1,9,5]\n",
    "name.reverse()\n",
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "f35dc292",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 5, 4, 2, 1]"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = [2,4,1,9,5]\n",
    "name.sort(reverse = True)\n",
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "69c903d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 4, 5, 9]"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = [2,4,1,9,5]\n",
    "name.sort(reverse = False)\n",
    "name"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24de23d2",
   "metadata": {},
   "source": [
    "### 加法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "4b63fed1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6]"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li = [1,2,3]\n",
    "st = [4,5,6]\n",
    "li+st"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6bf613b4",
   "metadata": {},
   "source": [
    "### 乘法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "7694e153",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 1, 2, 3]"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li*2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a18bab8",
   "metadata": {},
   "source": [
    "### 拷贝"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "6b0b21c3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li = [1,2,3]\n",
    "li1 = li.copy()\n",
    "li1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "c2fbf903",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4]"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li.append(4)\n",
    "li"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "a2eb9ec2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "47135ccb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import copy\n",
    "li = [1,2,3]\n",
    "li1 = copy.deepcopy(li)\n",
    "li1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "abec793b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4]"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li.append(4)\n",
    "li"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "9dbe64b4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "li1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c66bf1b6",
   "metadata": {},
   "source": [
    "### 访问嵌套列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "28cb9856",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[1, 2, 3], [4, 5, 6]]"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = [[1,2,3],[4,5,6]]\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "917ed733",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "for i in m:\n",
    "    for g in i:\n",
    "        print(g)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "f0c98988",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123\n",
      "456\n"
     ]
    }
   ],
   "source": [
    "for i in m:\n",
    "    for g in i:\n",
    "        print(g,end = '')\n",
    "    print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24c0bf2e",
   "metadata": {},
   "source": [
    "## 表格形式总结列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15c101fa",
   "metadata": {},
   "source": [
    "|列表的方法|描述|使用方法|备注|\n",
    "|:---|:---|:---|---|\n",
    "|list[start:stop:step]|列表的切片|list[start:stop:step]|可设开始、结束值、步长|\n",
    "|extend()|在列表末尾添加元素|list.extend(obj)|注意：只接受列表|\n",
    "|append()|在列表末尾添加元素|list.append(obj)|\n",
    "|insert(index,obj)|在列表的索引位置插入元素|\n",
    "|remove()|删除列表中的元素|list.remove(obj)|\n",
    "|pop()|删除列表中的元素|list.pop(index)|注意：pop与remove不同，是通过索引值指定删除，使用pop()可直接删除最后一位|\n",
    "|clear()|清空列表中的元素|list.clear()|\n",
    "|list[index] = \"obj\"|对列表中的元素进行替换|list[index] = \"obj\"|\n",
    "|sort()|对列表中的元素进行从小到大排序|list.sort()|\n",
    "|reverse()|将列表中的元素位置翻转|list.reverse()|注意：reverse = True/False,默认值为False|\n",
    "|in|检查元素是否为列表中的成员,返回值为True或False|obj in list|\n",
    "|count()|查找某个元素在列表中出现的次数|list.count(obj)|\n",
    "|index()|查找某个元素在列表中的索引值|list.index(obj)|\n",
    "|+|列表的加法计算|list1+list2|\n",
    "|*|列表的乘法计算|list1*list2|"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d61b1842",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
